package com.stm.web.controller.basicData;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stm.basicData.domain.KfToolsRequester;
import com.stm.basicData.service.KfToolsRequesterService;
import com.stm.common.annotation.Log;
import com.stm.common.core.controller.BaseController;
import com.stm.common.core.domain.AjaxResult;
import com.stm.common.core.page.TableDataInfo;
import com.stm.common.enums.BusinessType;
import com.stm.common.utils.poi.ExcelUtil;
import com.stm.framework.util.ShiroUtils;

/**
 * 委托单位 信息操作处理
 *
 * @author wyc
 * @date 2019-04-04
 */
@Controller
@RequestMapping("/basicData/kfToolsRequester")
public class ToolsRequesterController extends BaseController {
    private String prefix = "basicData/kfToolsRequester";

    @Autowired
    private KfToolsRequesterService kfToolsRequesterService;

    @RequiresPermissions("basicData:kfToolsRequester:view")
    @GetMapping()
    public String KfToolsRequester(ModelMap mmap)
    {
    	mmap.put("user", ShiroUtils.getSysUser());
        return prefix + "/KfToolsRequester";
    }

    /**
     * 查询委托单位列表
     */
    @RequiresPermissions("basicData:kfToolsRequester:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KfToolsRequester kfToolsRequester) {
        startPage();
        List<KfToolsRequester> list = kfToolsRequesterService.selectKfToolsRequesterList(kfToolsRequester);
        return getDataTable(list);
    }


    /**
     * 导出委托单位列表
     */
    @RequiresPermissions("basicData:kfToolsRequester:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KfToolsRequester kfToolsRequester) {
        List<KfToolsRequester> list = kfToolsRequesterService.selectKfToolsRequesterList(kfToolsRequester);
        ExcelUtil<KfToolsRequester> util = new ExcelUtil<KfToolsRequester>(KfToolsRequester.class);
        return util.exportExcel(list, "KfToolsRequester");
    }

    /**
     * 新增委托单位
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 查看厂家详情
     */
    @RequiresPermissions("basicData:kfToolsRequester:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") String id, ModelMap mmap) {
    	
        mmap.put("KfToolsRequester", kfToolsRequesterService.selectKfToolsRequesterById(id));
        return prefix + "/detail";
    }

    /**
     * 新增保存委托单位
     */
    @RequiresPermissions("basicData:kfToolsRequester:add")
    @Log(title = "委托单位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KfToolsRequester kfToolsRequester) {
    	kfToolsRequester.setCreateBy(ShiroUtils.getLoginName());
    	kfToolsRequester.setDprtcode(ShiroUtils.getSysUser().getDeptId());
        return toAjax(kfToolsRequesterService.insertKfToolsRequester(kfToolsRequester));
    }

    /**
     * 修改委托单位
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        KfToolsRequester kfToolsRequester = kfToolsRequesterService.selectKfToolsRequesterById(id);
        mmap.put("kfToolsRequester", kfToolsRequester);
        return prefix + "/edit";
    }

    /**
     * 修改保存委托单位
     */
    @RequiresPermissions("basicData:kfToolsRequester:edit")
    @Log(title = "委托单位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KfToolsRequester kfToolsRequester) {
    	kfToolsRequester.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(kfToolsRequesterService.updateKfToolsRequester(kfToolsRequester));
    }

    /**
     * 删除委托单位
     */
    @RequiresPermissions("basicData:kfToolsRequester:remove")
    @Log(title = "委托单位", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(kfToolsRequesterService.deleteKfToolsRequesterByIds(ids));
    }

    /**
     * @param user
     * @return
     * @Description 初始化委托单位下拉框数据
     * @CreateTime 2019年4月8日 上午11:22:58
     * @CreateBy 林龙
     */
    @PostMapping("/initRequester")
    @ResponseBody
    public List<KfToolsRequester> initRequester(KfToolsRequester kfToolsRequester) {
        return kfToolsRequesterService.selectKfToolsRequesterList(kfToolsRequester);
    }
}
